var baseUrl = '<?php echo $this->pluginUrl;?>';
var baseUrlGallery ='';
var sessionID = null;
var jQloaderAnimation, jQselectList, jQimageList;
var _once = '<?php echo wp_create_nonce("photoxhibit_")?>';

function isInteger (s){
	var i;

	if (isEmpty(s))
		if ( isInteger.arguments.length == 1 ) return 0;
	else return ( isInteger.arguments[1] == true );
		for ( i = 0; i < s.length; i++ ){
			var c = s.charAt(i);
	     	if (!isDigit(c)) return false;
		};
	return true;
};

function isEmpty(s){
      return ((s == null) || (s.length == 0))
};

function isDigit (c){
	return ((c >= "0") && (c <= "9"));
};

(function($){
	showNoticeMessage = function(cls, message){
		var jQthis = $('#px_message');
		jQthis.show().removeClass().addClass('fade').addClass(cls).html('<p>'+message+'</p>');
	
		setTimeout(function(){
			jQthis.slideUp().fadeOut();
		}, 5000);
	};
	$(document).ready(function(){
		jQloaderAnimation = $('#loaderAnimation');
		
		$('.px_optDelete')
		.click(function(){
			var answer = confirm("Are you sure you want to delete?")
			if (answer){
				return true;
			}
			else{
				return false;
			};
		});
		
		var jQinputs = $('#imgAltTable input[name=photo_alt]');
		var TO = Object();
		jQinputs.keyup(function(){
			var jQthis = $(this);
			var id = jQthis.attr('id');
			clearTimeout(TO[id]);
			TO[id] = setTimeout(function(){
				var value = jQthis.val();
				jQthis.parent().next().text('Alt text is being updated');		
				$.ajax({
					url : baseUrl + "editAttrAction",
					data : 'pxiid='+id.split('-').pop()+'&value='+value,
					dataType : 'json',
					success : function(data, textStatus){
						if(data.error == 'error_no_styles'){
							//alert('Sorry, but the styles were not passed to the server, please try again.');
						}
						else if(data.error == 'error_no_id'){
							//alert('Sorry, but the ID was not passed to the server, please try again.');
						}
						else{
							jQthis.parent().next().text('<?php _e('Alt text has been updated', 'photoxhibit');?>');
						};
					}				
				});
			}, 1000);
		});
	});
})(pxjQuery);